package com.controller;

import com.entity.*;
import com.entity.Class;
import com.service.ActivityParticipateService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;

@RestController
public class ActivityParticipateController {
    private  String path = new File(System.getProperty("user.dir")).toString()+"\\static\\img\\";

    @Autowired
    ActivityParticipateService activityParticipateService;

    @PostMapping("addClass")
    public String addClass(@RequestBody List<Class> data){
        boolean  state = activityParticipateService.addClassa(data);
        return "{\"state\":"+state+"}";
    }
    @PostMapping("addStudent")
    public Object addStudent(@RequestBody List<Student> students){

        Object  state = activityParticipateService.addStudent(students);
        return state;
    }
    /*
    查询班级
    data{
        proID: 活动id
    }
     */
    @PostMapping("queryClass")
    public Object queryClass(@RequestBody String data){
        JSONObject json = JSONObject.fromObject(data);
        System.out.println(json);
        return activityParticipateService.selectClasss((int)json.get("proID"),json.getString("school"));
    }
    /*
        查询班级内所有的学生
        {
            proID: 活动ID
            classe: 班级
            school：学校
        }
     */
    @PostMapping("queryStudets")
    public Object queryStudent(@RequestBody Student student){

        return  activityParticipateService.selectStudentS( student);
    }

    /*
        input学生查询
        UserName:姓名
        proID:活动id
     */
    @GetMapping("inputStudents")
    public Object inputStudents(String name,int proID){

        return activityParticipateService.selectInputStudents(name,proID);
    }


    @PostMapping("changeCase")
    public Object changeCase(@RequestBody Student student){
        return activityParticipateService.changeCase(student);
    }


    /*
        添加寝室
     dorNumber:寝室号
     base:基地
     bendNumber:可住人数
     location:地址
     */
    @PostMapping("addDorm")
    public Object addDorm(@RequestBody List<Dorm> dorms){
        System.out.println(dorms);
        return activityParticipateService.addDorm(dorms);
    }
    /**
     * 查询所有寝室
     */
    @PostMapping("queryDorms")
    public Object queryDorms(@RequestBody Paging paging){
        return activityParticipateService.selectDorms(paging);
    }

    /**
     * 删除寝室
     * @param dormIDs：寝室编号集合
     * @return
     */
    @PostMapping("delectDorm")
    public Object delectDorm(@RequestBody List<Integer> dormIDs){
        return activityParticipateService.delectDorm(dormIDs);
    }
    /*
        表单查询寝室信息
     */
    @GetMapping("intputQueryDorms")
    public Object intputQueryDorms( String params){
        return  activityParticipateService.intputQueryDorms(params);
    }
}
